﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XWord.Fundamental.Domain
{
    public class EtymaMessage
    {
        public EtymaMessage()
        {
            Name = string.Empty;
        }

        public EtymaMessage(string text)
        {
            Name = string.Empty;
            ParseEtyma(text);
        }

        public string Name { get; set; }

        public EtymaType EtymaType { get; set; }

        private static char[] filters = new char[] { '-', '+' };



        public void ParseEtyma(string text)
        {
            if (text.EndsWith("-"))
            {
                this.EtymaType = EtymaType.PreFix;
            }
            else if (text.StartsWith("-") && !text.EndsWith("+"))
            {
                this.EtymaType = EtymaType.Suffix;
            }
            else if (text.EndsWith("+"))
            {
                this.EtymaType =EtymaType.Etymon;
            }
            var sb = new StringBuilder(text.Length);
            foreach (var item in text)
            {
                if (!filters.Contains(item))
                {
                    sb.Append(item);
                }
            }
            this.Name = sb.ToString().Trim();
        }
    }
}
